package com.类加载器;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class 反射 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
        Class<?> c=Class.forName("com.类加载器.Text");
        Constructor<?> ct=c.getDeclaredConstructor(String.class);
        ct.setAccessible(true);
        Text t= (Text)ct.newInstance("刘观圣");
        System.out.println(t.name);
        System.out.println(" - - - - - - - -  - - - -  - - - - ");
        Class<Text> cc=Text.class;
        Field[] f= cc.getDeclaredFields();
        for(Field ff:f){
            System.out.println(ff);
        }
        Constructor<?> cst=cc.getConstructor();
        Text tx=(Text)cst.newInstance();
        System.out.println(tx);
        System.out.println(" - - - - - - - -  - - - -  - - - - ");
        Field name=c.getDeclaredField("name");
        name.setAccessible(true);



    }
}
